package no.uib.jexpress_modularized.somclust.visualization;

import java.awt.Color;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.io.Serializable;
import javax.swing.SpinnerNumberModel;
import no.uib.jexpress_modularized.core.model.SelectionChangeListener;
import no.uib.jexpress_modularized.somclust.model.ClusterSettings;

/**
 * A panel used to display and interact with hierarchical clustering results.
 * (Based on the old MainClust2Window from J-Express.)
 *
 * @author Bjarte Dysvik
 * @author Harald Barsnes
 * @author Yehia Farag (updates)
 */
public class HierarchicalClusteringPanel extends javax.swing.JPanel implements SelectionChangeListener , Serializable{

    /**
     * The dataset used as the basis for the clustering.
     */
    /**
     * The clustering parameters.
     */
    /**
     * Contains the actual clustering results.
     */
    private MainClustComponent clust;

    /**
     * Creates a new HierarchicalClusteringPanel.
     *
     * @param data the original dataset
     * @param pm the clusterig paramaters
     * @param result  
     */
   

    /**
     * Creates a new HierarchicalClusteringPanel.
     *
     * @param clustview the MainClustComponent
     */
    
      public HierarchicalClusteringPanel(MainClustComponent clustview) {
        initComponents();
        
        this.clust = clustview;       
        drawingPanel.add(clust);
        this.clust.addKeyListener(new KeyAdapter() {
            @Override
            public void keyReleased(KeyEvent e) {
                if (e.getKeyCode() == KeyEvent.VK_COPY 
                        || (e.isControlDown() && e.getKeyCode() == KeyEvent.VK_C)) {
                   clust.copySelectionText();
                }
            }
        });

        initControllers();
        doLayout();
        revalidate();
        updateForm(new ClusterSettings());  
    }
      @Override
       public void selectionChanged(no.uib.jexpress_modularized.core.model.Selection.TYPE type) {
        clust.repaint();
    }
     

    /**
     * Initiate the values in the controllers.
     */
    private void initControllers() {
        Integer value = new Integer(2);
        Integer min = new Integer(1);
        Integer max = new Integer(25);
        Integer step = new Integer(1);
        SpinnerNumberModel model = new SpinnerNumberModel(value, min, max, step);
        SpinnerNumberModel model2 = new SpinnerNumberModel(value, min, max, step);
        markColorButton.setColor(Color.red);        
        brickHeightSpinner.setModel(model);
        breakWidthSpinner.setModel(model2);
    }

    /**
     * Update the display settings.
     *
     * @param cs the cluster settings
     */
    private void updateForm(ClusterSettings cs) {
        leftTreeWidthTextField.setText(Integer.toString(cs.getLeftTreeSize()));
        upperTreeHeightTextField.setText(Integer.toString(cs.getTopTreeSize()));

        brickHeightSpinner.setValue(new Integer(cs.getSquareL()));
        breakWidthSpinner.setValue(new Integer(cs.getSquareW()));

        markColorButton.setColor(cs.getMarkColor());
        gridCheckBox.setSelected(cs.paintGrid());
    }

    /**
     * Update the cluster settings based on the currently selected values.
     */
    private void updateClusterSettings() {

        ClusterSettings cs = new ClusterSettings();
        cs.setGrid(gridCheckBox.isSelected());

        try {
            int tw = Integer.parseInt(leftTreeWidthTextField.getText());
            int th = Integer.parseInt(upperTreeHeightTextField.getText());
            cs.setLeftTreeSize(tw);
            cs.setTopTreeSize(th);
        } catch (Exception e) {
            e.printStackTrace();
        }

        cs.setMarkColor(markColorButton.getColor());
        cs.setSquareL(((Integer) brickHeightSpinner.getValue()).intValue());
        cs.setSquareW(((Integer) breakWidthSpinner.getValue()).intValue());
        clust.setClusterSettings(cs);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        backgroundPanel = new javax.swing.JPanel();
        drawingPanel = new javax.swing.JPanel();
        settingsPanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        brickHeightSpinner = new javax.swing.JSpinner();
        breakWidthSpinner = new javax.swing.JSpinner();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        leftTreeWidthTextField = new javax.swing.JTextField();
        upperTreeHeightTextField = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        markColorButton = new no.uib.jexpress_modularized.core.visualization.ColorButton();
        gridCheckBox = new javax.swing.JCheckBox();
        tooltipButton = new no.uib.jexpress_modularized.core.visualization.TooltipButton();
        buttonBar = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();
        saveButton = new javax.swing.JButton();
        printButton = new javax.swing.JButton();
        jLabel124 = new javax.swing.JLabel();
        createDendrogramGroupsButton = new javax.swing.JButton();
        jLabel122 = new javax.swing.JLabel();
        clearTreeSelectionsButton = new javax.swing.JToggleButton();

        backgroundPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(3, 3, 3, 3));

        drawingPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(2, 2, 2, 2));
        drawingPanel.setLayout(new java.awt.BorderLayout());

        settingsPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(160, 160, 160)));

        jLabel1.setText("Brick Height:");

        jLabel2.setText("Brick Width:");

        brickHeightSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                brickHeightSpinnerStateChanged(evt);
            }
        });

        breakWidthSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                breakWidthSpinnerStateChanged(evt);
            }
        });

        jLabel3.setText("Left Tree Width:");

        jLabel4.setText("Upper Tree Heigth:");

        leftTreeWidthTextField.setColumns(4);
        leftTreeWidthTextField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        leftTreeWidthTextField.setText("200");
        leftTreeWidthTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                leftTreeWidthTextFieldKeyReleased(evt);
            }
        });

        upperTreeHeightTextField.setColumns(4);
        upperTreeHeightTextField.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        upperTreeHeightTextField.setText("100");
        upperTreeHeightTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                upperTreeHeightTextFieldKeyReleased(evt);
            }
        });

        jLabel5.setText("Mark Color:");

        markColorButton.setText("colorButton1");
        markColorButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
        markColorButton.setPreferredSize(new java.awt.Dimension(29, 13));
        markColorButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                markColorButtonActionPerformed(evt);
            }
        });
        markColorButton.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                markColorButtonPropertyChange(evt);
            }
        });

        gridCheckBox.setSelected(true);
        gridCheckBox.setText("Grid");
        gridCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        gridCheckBox.setIconTextGap(10);
        gridCheckBox.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                gridCheckBoxItemStateChanged(evt);
            }
        });

        tooltipButton.setToolTipText("Dendrogram parameters<D><b>Where is the annotation?</b> - Set the brick height higher so the annotation gets enough space<br><b>Brick width</b> - The width of each color brick in the heat map<br><b>Left tree width and upper tree height</b> - the size of the trees<br><b>Mark color</b> - when in set branch color mode (click the pencil) you can set the branch color with this color<br><b>Grid</b> - Toggle on and off a grid");

        javax.swing.GroupLayout tooltipButtonLayout = new javax.swing.GroupLayout(tooltipButton);
        tooltipButton.setLayout(tooltipButtonLayout);
        tooltipButtonLayout.setHorizontalGroup(
            tooltipButtonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 19, Short.MAX_VALUE)
        );
        tooltipButtonLayout.setVerticalGroup(
            tooltipButtonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout settingsPanelLayout = new javax.swing.GroupLayout(settingsPanel);
        settingsPanel.setLayout(settingsPanelLayout);
        settingsPanelLayout.setHorizontalGroup(
            settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, settingsPanelLayout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(settingsPanelLayout.createSequentialGroup()
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(breakWidthSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(upperTreeHeightTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(gridCheckBox)
                        .addContainerGap(378, Short.MAX_VALUE))
                    .addGroup(settingsPanelLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(brickHeightSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(leftTreeWidthTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(markColorButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 279, Short.MAX_VALUE)
                        .addComponent(tooltipButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(21, 21, 21))))
        );

        settingsPanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel1, jLabel2});

        settingsPanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel3, jLabel4});

        settingsPanelLayout.setVerticalGroup(
            settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, settingsPanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel1)
                    .addComponent(brickHeightSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(leftTreeWidthTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tooltipButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(markColorButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel2)
                    .addComponent(breakWidthSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(upperTreeHeightTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(gridCheckBox))
                .addContainerGap())
        );

        settingsPanelLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {breakWidthSpinner, brickHeightSpinner, leftTreeWidthTextField, upperTreeHeightTextField});

        settingsPanelLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jLabel5, markColorButton});

        buttonBar.setLayout(new javax.swing.BoxLayout(buttonBar, javax.swing.BoxLayout.LINE_AXIS));

        jLabel12.setText("  ");
        buttonBar.add(jLabel12);

        saveButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/save.gif"))); // NOI18N
        saveButton.setToolTipText("Save Image");
        saveButton.setActionCommand("save");
        saveButton.setBorder(null);
        saveButton.setBorderPainted(false);
        saveButton.setContentAreaFilled(false);
        saveButton.setMaximumSize(new java.awt.Dimension(22, 22));
        saveButton.setMinimumSize(new java.awt.Dimension(22, 22));
        saveButton.setPreferredSize(new java.awt.Dimension(22, 22));
        saveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveButtonActionPerformed(evt);
            }
        });
        buttonBar.add(saveButton);

        printButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/printer.gif"))); // NOI18N
        printButton.setToolTipText("Print Image");
        printButton.setActionCommand("print");
        printButton.setBorder(null);
        printButton.setBorderPainted(false);
        printButton.setContentAreaFilled(false);
        printButton.setMaximumSize(new java.awt.Dimension(22, 22));
        printButton.setMinimumSize(new java.awt.Dimension(22, 22));
        printButton.setPreferredSize(new java.awt.Dimension(22, 22));
        printButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                printButtonActionPerformed(evt);
            }
        });
        buttonBar.add(printButton);

        jLabel124.setMaximumSize(new java.awt.Dimension(4, 17));
        jLabel124.setMinimumSize(new java.awt.Dimension(4, 17));
        jLabel124.setPreferredSize(new java.awt.Dimension(4, 17));
        buttonBar.add(jLabel124);

        createDendrogramGroupsButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/classes.gif"))); // NOI18N
        createDendrogramGroupsButton.setToolTipText("<html>\nCreate Groups<br>\nof Dendrograms\n</html>");
        createDendrogramGroupsButton.setActionCommand("sets");
        createDendrogramGroupsButton.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(150, 200, 150), 1, true));
        createDendrogramGroupsButton.setBorderPainted(false);
        createDendrogramGroupsButton.setContentAreaFilled(false);
        createDendrogramGroupsButton.setMaximumSize(new java.awt.Dimension(22, 22));
        createDendrogramGroupsButton.setMinimumSize(new java.awt.Dimension(22, 22));
        createDendrogramGroupsButton.setPreferredSize(new java.awt.Dimension(22, 22));
        createDendrogramGroupsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                createDendrogramGroupsButtonActionPerformed(evt);
            }
        });
        buttonBar.add(createDendrogramGroupsButton);

        jLabel122.setMaximumSize(new java.awt.Dimension(4, 17));
        jLabel122.setMinimumSize(new java.awt.Dimension(4, 17));
        jLabel122.setPreferredSize(new java.awt.Dimension(4, 17));
        buttonBar.add(jLabel122);

        clearTreeSelectionsButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/hclustremovecolor.gif"))); // NOI18N
        clearTreeSelectionsButton.setToolTipText("Clear Tree Selections");
        clearTreeSelectionsButton.setActionCommand("hremovecolor");
        clearTreeSelectionsButton.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(150, 200, 150)));
        clearTreeSelectionsButton.setBorderPainted(false);
        clearTreeSelectionsButton.setContentAreaFilled(false);
        clearTreeSelectionsButton.setFocusPainted(false);
        clearTreeSelectionsButton.setMaximumSize(new java.awt.Dimension(22, 22));
        clearTreeSelectionsButton.setMinimumSize(new java.awt.Dimension(22, 22));
        clearTreeSelectionsButton.setPreferredSize(new java.awt.Dimension(22, 22));
        clearTreeSelectionsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearTreeSelectionsButtonActionPerformed(evt);
            }
        });
        buttonBar.add(clearTreeSelectionsButton);

        javax.swing.GroupLayout backgroundPanelLayout = new javax.swing.GroupLayout(backgroundPanel);
        backgroundPanel.setLayout(backgroundPanelLayout);
        backgroundPanelLayout.setHorizontalGroup(
            backgroundPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(settingsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(buttonBar, javax.swing.GroupLayout.DEFAULT_SIZE, 817, Short.MAX_VALUE)
            .addComponent(drawingPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 817, Short.MAX_VALUE)
        );
        backgroundPanelLayout.setVerticalGroup(
            backgroundPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(backgroundPanelLayout.createSequentialGroup()
                .addComponent(buttonBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0)
                .addComponent(drawingPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 461, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(settingsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 823, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(backgroundPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 565, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(backgroundPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Updates the cluster settings.
     *
     * @param evt
     */
    private void brickHeightSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_brickHeightSpinnerStateChanged
        updateClusterSettings();
    }//GEN-LAST:event_brickHeightSpinnerStateChanged

    /**
     * Updates the cluster settings.
     *
     * @param evt
     */
    private void breakWidthSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_breakWidthSpinnerStateChanged
        updateClusterSettings();
    }//GEN-LAST:event_breakWidthSpinnerStateChanged

    /**
     * Updates the cluster settings.
     *
     * @param evt
     */
    private void leftTreeWidthTextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_leftTreeWidthTextFieldKeyReleased
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            updateClusterSettings();
        }
    }//GEN-LAST:event_leftTreeWidthTextFieldKeyReleased

    /**
     * Updates the cluster settings.
     *
     * @param evt
     */
    private void upperTreeHeightTextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_upperTreeHeightTextFieldKeyReleased
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            updateClusterSettings();
        }
    }//GEN-LAST:event_upperTreeHeightTextFieldKeyReleased

    /**
     * Updates the mark color.
     *
     * @param evt
     */
    private void markColorButtonPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_markColorButtonPropertyChange
        if (evt.getPropertyName().equals("Color changed")) {
            clust.setMarkColor(markColorButton.getColor());
        }
    }//GEN-LAST:event_markColorButtonPropertyChange

    /**
     * Updates the cluster settings.
     *
     * @param evt
     */
    private void gridCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_gridCheckBoxItemStateChanged
        updateClusterSettings();
    }//GEN-LAST:event_gridCheckBoxItemStateChanged

    /**
     * Clears the tree selections.
     *
     * @param evt
     */
    private void clearTreeSelectionsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearTreeSelectionsButtonActionPerformed
        clust.clearTreeColors(clust.getLeftRoot());
        clust.clearTreeColors(clust.getTopRoot());
    }//GEN-LAST:event_clearTreeSelectionsButtonActionPerformed

    /**
     * Creates dendrogram groups.
     *
     * @param evt
     */
    private void createDendrogramGroupsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createDendrogramGroupsButtonActionPerformed
                
        clust.createGroupOfSelection();
        clust.repaint();
    }//GEN-LAST:event_createDendrogramGroupsButtonActionPerformed

    /**
     * Prints the image.
     *
     * @param evt
     */
    private void printButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_printButtonActionPerformed
        clust.printim();
    }//GEN-LAST:event_printButtonActionPerformed

    /**
     * Saves the image.
     *
     * @param evt
     */
    private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
        clust.saveImage();
    }//GEN-LAST:event_saveButtonActionPerformed

    private void markColorButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_markColorButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_markColorButtonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel backgroundPanel;
    private javax.swing.JSpinner breakWidthSpinner;
    private javax.swing.JSpinner brickHeightSpinner;
    public javax.swing.JPanel buttonBar;
    private javax.swing.JToggleButton clearTreeSelectionsButton;
    public javax.swing.JButton createDendrogramGroupsButton;
    private javax.swing.JPanel drawingPanel;
    private javax.swing.JCheckBox gridCheckBox;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel122;
    private javax.swing.JLabel jLabel124;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JTextField leftTreeWidthTextField;
    private no.uib.jexpress_modularized.core.visualization.ColorButton markColorButton;
    public javax.swing.JButton printButton;
    public javax.swing.JButton saveButton;
    private javax.swing.JPanel settingsPanel;
    private no.uib.jexpress_modularized.core.visualization.TooltipButton tooltipButton;
    private javax.swing.JTextField upperTreeHeightTextField;
    // End of variables declaration//GEN-END:variables

    
  
}
